package com.heima.wemedia.feign;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.mapper.WmUserMapper;
import com.heima.wemedia.service.WmChannelService;
import com.zxc.apis.wemedia.IWemediaClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class WemediaClient implements IWemediaClient {
    @Resource
    private WmChannelService wmChannelService;

    @Resource
    private WmUserMapper wmUserMapper;

    @GetMapping("/api/v1/user/findUser/{name}")
    @Override
    public WmUser findUserByName(@PathVariable("name") String ApUserName) {
        return wmUserMapper.selectOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, ApUserName));
    }

    @PostMapping("/api/v1/user/save")
    @Override
    public ResponseResult save(WmUser wmUser) {
        wmUserMapper.insert(wmUser);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @GetMapping("/api/v1/channel/findChannels")
    @Override
    public ResponseResult findChannels() {
        System.out.println("======================================");
        return wmChannelService.findChannels();
    }
}
